/**
 * @author junyu33
 * 2022,05,07
 */
import java.util.Vector;

public class Society {
    private String name;
    /**
     * a instance of management committee
     */
    private ManagementCttee mCttee = new ManagementCttee();
    /**
     * list of members
     */
    private Vector<Member> members = new Vector<Member>();

    /**
     * construct method
     * initialize society's name
     * @param name
     */
    public Society(String name) {
        this.name = name;
    }

    /**
     * get society's name
     * @return name
     */
    public String getName() {
        return this.name;
    }

    /**
     * add a standard member by name and address
     * @param name
     * @param address
     */
    public void addMember(String name, String address) {
        for(Member i : members) {
            if(i.getName().equals(name)) {
                System.out.println("This person already exists!");
                return;
            }
        }
        Member m = new StandardMember(name, address);
        members.addElement(m);
    }

    /**
     * add a senior member by name, address and fee
     * @param name
     * @param address
     * @param fee
     */
    public void addSeniorMember(String name, String address, int fee) {
        for(Member i : members) {
            if(i.getName().equals(name)) {
                System.out.println("This person already exists!");
                return;
            }
        }
        Member m = new SeniorMember(name, address, fee);
        members.addElement(m);
    }

    /**
     * find a senior member by its name
     * @param name
     * @return a senior member
     */
    public SeniorMember findSeniorMember(String name) {
        for(Member i : members) {
            if(i.getName().equals(name))
                if(i instanceof SeniorMember)
                    return (SeniorMember) i;
        }
        System.out.println("Can't find any result, this person does not exist or he/she isn't senior member.");
        return null;
    }

    /**
     * add a committee member from a senior member
     * @param member
     */
    public void addCtteeMember(SeniorMember member) {
        mCttee.addCtteeMember(member);
    }

    /**
     * get total fee
     * @return total fee
     */
    public int getFeeTotal() {
        int total = 0;
        for(Member m : members) {
            total += m.getFee();
        }
        return total;
    }

    /**
     * show all members' info
     */
    public void showInfo() {
        System.out.println("Senior members:");
        for(Member i : members) {
            if(i instanceof SeniorMember) {
                System.out.println("Name: " + i.getName());
                System.out.println("Address: " + i.getAddress());
                System.out.println("Fee: " + i.getFee());
                System.out.println();
            }
        }
        System.out.println();

        System.out.println("Standard members:");
        for(Member i : members) {
            if(i instanceof StandardMember) {
                System.out.println("Name: " + i.getName());
                System.out.println("Address: " + i.getAddress());
                System.out.println();
            }
        }
        System.out.println();

        mCttee.showCtteeMember();
    }
}
